#ifndef STX_ALGORITHM_FIND_FIRST_OF_HPP
#define STX_ALGORITHM_FIND_FIRST_OF_HPP

#include <stx/algorithm/common.hpp>

namespace stx {

template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
ForwardIterator1
find_first_of(
    ForwardIterator1 first1,
    ForwardIterator1 last1,
    ForwardIterator2 first2,
    ForwardIterator2 last2,
    BinaryPredicate pred)
{
    for (; first1 != last1; ++first1) {
        for (ForwardIterator2 j = first2; j != last2; ++j) {
            if (pred(*first1, *j)) {
                return first1;
            }
        }
    }
    return last1;
}

template <class ForwardIterator1, class ForwardIterator2>
inline ForwardIterator1
find_first_of(
    ForwardIterator1 first1,
    ForwardIterator1 last1,
    ForwardIterator2 first2,
    ForwardIterator2 last2)
{
    typedef typename std::iterator_traits<ForwardIterator1>::value_type v1;
    typedef typename std::iterator_traits<ForwardIterator2>::value_type v2;
    return stx::find_first_of(first1, last1, first2, last2, equal_to<v1, v2>());
}

} // namespace stx

#endif // STX_ALGORITHM_FIND_FIRST_OF_HPP
